package com.xike.microsysserver.controller;//package com.woniuxy.microsysserver.serurity.acl;

import com.alibaba.fastjson.JSONObject;
import com.xike.microsysserver.entity.acl.User;
import com.xike.microsysserver.service.IndexService;
import com.xike.microsysserver.uitl.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RefreshScope
@Api("获取菜单列表和权限列表")
@RestController
@RequestMapping("/admin/acl/index")
public class IndexController {

    @Autowired(required = false)
    private IndexService indexService;

    /**
     * 根据token获取用户信息
     */
    @ApiOperation("获取用户信息")
    @PostMapping("info")
    public ResponseEntity info (@RequestBody User user) {
        //获取当前登录用户用户名
//        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        Map<String, Object> userInfo = indexService.getUserInfo(user.getUsername());
        return ResponseEntity.ok().data(userInfo);
    }

    /**
     * 获取菜单
     *
     * @return
     */
    @ApiOperation("获取菜单信息")
    @PostMapping("menu")
    public ResponseEntity getMenu (@RequestBody User user) {
        //获取当前登录用户用户名
//        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        List<JSONObject> permissionList = indexService.getMenu(user.getUsername());
        return ResponseEntity.ok().data("permissionList", permissionList);
    }

    @PostMapping("logout")
    public ResponseEntity logout () {
        return ResponseEntity.ok();
    }

}
